

import java.net.MalformedURLException;
import java.nio.file.Path;

import db.DBManager;
import db.Tag;


public class StartTag {
	public String curr;
	DBManager db;
	
	public StartTag(String curr) {
		this.curr=curr;
		db = new DBManager();
	}
	
	public void setCurr(String curr){
		this.curr=curr;
	}
	
	public void createTag(Path p) throws ClassNotFoundException, MalformedURLException, InstantiationException, IllegalAccessException{
		String[] tags;
		TagsLoader tl= new TagsLoader();
		Tag t = new Tag();
		String str = p.toString();
		String splitPath[] = str.split("\\\\");
		int last = splitPath.length;
		t.setFile((splitPath[last-1]));
		tags = tl.LoadTag(p.toString(), curr);
		if (tags == null){
			System.out.println("NO!");
			return;
		}
		int len = tags.length;
		for(int i = 0;i<len;i++){
			t.setTag(tags[i]);
			db.addTag(t);
		}
		
	}
	
	public void deleteTag(Path p){
		db.removeFile(p.toString());
	}

}
